package com.goldfish666.remote_control.controller.base;

import com.goldfish666.remote_control.exception.ApiNotExistException;
import com.goldfish666.remote_control.pojo.Result;
import com.goldfish666.remote_control.pojo.condition.KeywordCondition;
import com.goldfish666.remote_control.validator.CreateValidatorGroup;
import com.goldfish666.remote_control.validator.UpdateValidatorGroup;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@Validated
public interface BaseController<T, Condition extends KeywordCondition, ID> {


    /**
     * 获取查询分页数据
     *
     * @param condition 筛选条件
     * @param pageable  分页信息
     * @return 分页数据
     */
    @PostMapping("page")
    @ApiOperation("根据条件获取分页列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "condition", dataType = "KeywordCondition", dataTypeClass = KeywordCondition.class, value = "查询条件")})
    default Result<? extends Page<T>> getFilterList(@RequestBody(required = false) @Validated Condition condition, Pageable pageable) {
        throw new ApiNotExistException();
    }

    /**
     * 获取全部数据
     *
     * @return 全部数据
     */
    @GetMapping("all")
    @ApiOperation("获取全部")
    default Result<? extends List<T>> getAll() {
        throw new ApiNotExistException();
    }

    /**
     * 根据条件获取实体Id集合
     *
     * @param condition 筛选条件
     * @return 筛选后id集合
     */
    @PostMapping("ids")
    @ApiOperation("根据条件获取Id集合")
    @ApiImplicitParams({@ApiImplicitParam(name = "condition", dataType = "KeywordCondition", dataTypeClass = KeywordCondition.class, value = "查询条件")})
    default Result<? extends List<ID>> getIdsByFilter(@RequestBody(required = false) @Validated Condition condition) {
        throw new ApiNotExistException();
    }

    /**
     * 根据ID获取数据
     *
     * @param id id
     * @return 数据
     */
    @GetMapping("{id}")
    @ApiOperation(value = "根据ID获取详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", required = true, value = "ID", paramType = "path")})
    default Result<T> getById(@PathVariable("id") @NotNull(message = "id不能为空") ID id) {
        throw new ApiNotExistException();
    }

    /**
     * 保存数据
     *
     * @param t 实体数据
     * @return 保存后数据
     */
    @PostMapping
    @ApiOperation("保存")
    default Result<T> save(@RequestBody @Validated({CreateValidatorGroup.class}) T t) {
        throw new ApiNotExistException();
    }

    /**
     * 更新数据
     *
     * @param t 实体数据
     * @return 更新后数据
     */
    @PutMapping
    @ApiOperation("更新")
    default Result<T> update(@RequestBody @Validated({UpdateValidatorGroup.class}) T t) {
        throw new ApiNotExistException();
    }


    /**
     * 根据id删除数据
     *
     * @param id id
     * @return 删除后标志
     */
    @DeleteMapping("{id}")
    @ApiOperation("删除")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", required = true, value = "ID", paramType = "path")})
    default Result<Boolean> delete(@PathVariable("id") @NotNull(message = "id不能为空") ID id) {
        throw new ApiNotExistException();
    }

}
